<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表格隔行变色</title>
    <style>
        .bg{
            background-color: pink;
        }
    </style>
</head>
<body>
       <tbody>
           <tr>
               <td>11</td>
               <td>22</td>
               <td>33</td>
               <td>44</td>
           </tr>
           <tr>
            <td>11</td>
            <td>22</td>
            <td>33</td>
            <td>44</td>
        </tr>
       </tbody>
         
       <!-- 表格没写 下面是js 样式 -->
       <script>
        //    1 获取元素
           var trs = document.querySelector('tbody').querySelectorAll('tr');
        //    2 利用循环绑定注册事件
            for(var i = 0; i < trs.length; i++){
                //  鼠标经过事件 onmouseover
                trs[i].onmouseover = function(){
                    this.className = 'bg';

                }
                //  鼠标离开事件 onmouseout
                trs[i].onmouseout = function(){
                    this.className = '';
                }
                

            }
       </script>
</body>
</html>